<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <th:block th:include="include :: header('均线分析列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="col-sm-12 search-collapse">
           <!-- <form id="formId" class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">是否上穿5日均线：</label>
                    <div class="layui-input-inline">
                        <label>
                            <input type="radio" name="fiveFlag" class="layui-input" title="是" value="1">
                            <input type="radio" name="fiveFlag" class="layui-input" title="否" value="0">
                        </label>
                    </div>
                    <label class="layui-form-label">5日均线值：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="fiveValue" placeholder="请输入5日均线值"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">是否上穿10日均线：</label>
                    <div class="layui-input-inline">
                        <label>
                            <input type="radio" name="fiveFlag" class="layui-input" title="是" value="1">
                            <input type="radio" name="fiveFlag" class="layui-input" title="否" value="0">
                        </label>
                    </div>
                    <label class="layui-form-label">10日均线值：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="tenValue" placeholder="请输入10日均线值"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">是否上穿20日均线：</label>
                    <div class="layui-input-inline">
                        <label>
                            <input type="radio" name="fiveFlag" class="layui-input" title="是" value="1">
                            <input type="radio" name="fiveFlag" class="layui-input" title="否" value="0">
                        </label>
                    </div>
                    <label class="layui-form-label">20日均线值：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="twentyValue" placeholder="请输入20日均线值"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">是否上穿30日均线：</label>
                    <div class="layui-input-inline">
                        <label>
                            <input type="radio" name="fiveFlag" class="layui-input" title="是" value="1">
                            <input type="radio" name="fiveFlag" class="layui-input" title="否" value="0">
                        </label>
                    </div>
                    <label class="layui-form-label">30日均线值：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="thirtyValue" placeholder="请输入30日均线值"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">是否上穿60日均线：</label>
                    <div class="layui-input-inline">
                        <label>
                            <input type="radio" name="fiveFlag" class="layui-input" title="是" value="1">
                            <input type="radio" name="fiveFlag" class="layui-input" title="否" value="0">
                        </label>
                    </div>
                    <label class="layui-form-label">60日均线值：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sixtyValue" placeholder="请输入60日均线值"
                            class="layui-input" />
                    </div>
                    <label class="layui-form-label">是否上穿120日均线：</label>
                    <div class="layui-input-inline">
                        <label>
                            <input type="radio" name="fiveFlag" class="layui-input" title="是" value="1">
                            <input type="radio" name="fiveFlag" class="layui-input" title="否" value="0">
                        </label>
                    </div>
                    <label class="layui-form-label">120日均线值：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="ohtwentyValue" placeholder="请输入120日均线值"
                            class="layui-input" />
                    </div>
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="stockMa-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </form>-->
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="stockMa-table" lay-filter="stockMa-table"></table>
        <script type="text/html" id="stockMa-toolbar">
            <button sec:authorize="hasPermission('/stock/stockMa/add','stock:stockMa:add')"
                    class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                新增
            </button>
            <button sec:authorize="hasPermission('/stock/stockMa/remove','stock:stockMa:remove')"
                    class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                <i class="layui-icon layui-icon-delete"></i>
                删除
            </button>
        </script>
        <script type="text/html" id="stockMa-bar">
            <button sec:authorize="hasPermission('/stock/stockMa/edit','stock:stockMa:edit')"
                    class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i
                    class="layui-icon layui-icon-edit"></i>
            </button>
            <button sec:authorize="hasPermission('/stock/stockMa/remove','stock:stockMa:remove')"
                    class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
                    class="layui-icon layui-icon-delete"></i>
            </button>
        </script>
    </div>
</div>
<script id="stock-fiveFlag" type="text/html">
    {{#if (d.fiveFlag == 0) { }}
    <span>否</span>
    {{# }else if(d.fiveFlag == 1){ }}
    <span>是</span>
    {{# } }}
</script>
<script id="stock-tenFlag" type="text/html">
    {{#if (d.tenFlag == 0) { }}
    <span>否</span>
    {{# }else if(d.tenFlag == 1){ }}
    <span>是</span>
    {{# } }}
</script>
<script id="stock-twentyFlag" type="text/html">
    {{#if (d.twentyFlag == 0) { }}
    <span>否</span>
    {{# }else if(d.twentyFlag == 1){ }}
    <span>是</span>
    {{# } }}
</script>
<script id="stock-thirtyFlag" type="text/html">
    {{#if (d.thirtyFlag == 0) { }}
    <span>否</span>
    {{# }else if(d.thirtyFlag == 1){ }}
    <span>是</span>
    {{# } }}
</script>
<script id="stock-sixtyFlag" type="text/html">
    {{#if (d.sixtyFlag == 0) { }}
    <span>否</span>
    {{# }else if(d.sixtyFlag == 1){ }}
    <span>是</span>
    {{# } }}
</script>
<script id="stock-ohtwentyFlag" type="text/html">
    {{#if (d.ohtwentyFlag == 0) { }}
    <span>否</span>
    {{# }else if(d.ohtwentyFlag == 1){ }}
    <span>是</span>
    {{# } }}
</script>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery', 'dictionary', 'popup'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;

        let prefix = "/stock/stockMa/";

        let cols = [
            [
                {type: 'checkbox'},
                        {
                            field: 'id',
                            title: 'id(主键)',
                            hide: true
                        },
                        {
                            field: 'fiveFlag',
                            title: '是否上穿5日均线',
                            templet: '#stock-fiveFlag'
                        },
                        {
                            field: 'fiveValue',
                            title: '5日均线值'
                        },
                        {
                            field: 'tenFlag',
                            title: '是否上穿10日均线',
                            templet: '#stock-tenFlag'
                        },
                        {
                            field: 'tenValue',
                            title: '10日均线值'
                        },
                        {
                            field: 'twentyFlag',
                            title: '是否上穿20日均线',
                            templet: '#stock-twentyFlag'
                        },
                        {
                            field: 'twentyValue',
                            title: '20日均线值'
                        },
                        {
                            field: 'thirtyFlag',
                            title: '是否上穿30日均线',
                            templet: '#stock-thirtyFlag'
                        },
                        {
                            field: 'thirtyValue',
                            title: '30日均线值'
                        },
                        {
                            field: 'sixtyFlag',
                            title: '是否上穿60日均线',
                            templet: '#stock-sixtyFlag'
                        },
                        {
                            field: 'sixtyValue',
                            title: '60日均线值'
                        },
                        {
                            field: 'ohtwentyFlag',
                            title: '是否上穿120日均线',
                            templet: '#stock-ohtwentyFlag'
                        },
                        {
                            field: 'ohtwentyValue',
                            title: '120日均线值'
                        },
                        {
                            field: 'sumcount',
                            title: '上传数量'
                        },
                {title: '操作', toolbar: '#stockMa-bar', align: 'center', width: 130}
            ]
        ]

        table.render({
            elem: '#stockMa-table',
            url: prefix + 'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#stockMa-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(stockMa-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        table.on('toolbar(stockMa-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(stockMa-query)', function (data) {
            table.reload('stockMa-table', {where: data.field})
            return false;
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '新增均线分析',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'add'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改均线分析',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'edit?id=' + obj.data['id']
            });
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该均线分析', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "remove/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些均线分析', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "batchRemove",
                    dataType: 'json',
                    data: {"ids": ids},
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('stockMa-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('stockMa-table', {where: param});
        }
    })
</script>
</body>
</html>